* Clean up
clear all

/* Set working directory: please set your own
cd "~/Dropbox/JOP third submission/JOP replication/"
*/

* Open dataset
use 01_data/whole_spain.dta, clear

* Run analyses
reghdfe pp_voteshare post##ep##ciutadella if period > 1 & (turnout_above_median_p3 == 1 | turnout_above_median_p3 == 2), absorb(mesa_code_elecspecific) cluster(mesa_code_elecspecific)
est store twoperiods_hte_turnout_1

reghdfe pp_voteshare post##ep##ciutadella if period > 1 & (turnout_above_median_p3 == 0 | turnout_above_median_p3 == 2), absorb(mesa_code_elecspecific) cluster(mesa_code_elecspecific)
est store twoperiods_hte_turnout_2

reghdfe pp_voteshare post##ep##ciutadella if (turnout_above_median_p3 == 1 | turnout_above_median_p3 == 2), absorb(mesa_code_elecspecific) cluster(mesa_code_elecspecific)
est store twoperiods_hte_turnout_3

reghdfe pp_voteshare post##ep##ciutadella if (turnout_above_median_p3 == 0 | turnout_above_median_p3 == 2), absorb(mesa_code_elecspecific) cluster(mesa_code_elecspecific)
est store twoperiods_hte_turnout_4

reghdfe pp_voteshare post##ep##ciutadella i.period  if (turnout_above_median_p3 == 1 | turnout_above_median_p3 == 2), absorb(mesa_code_elecspecific) cluster(mesa_code_elecspecific)
est store twoperiods_hte_turnout_5

reghdfe pp_voteshare post##ep##ciutadella i.period  if (turnout_above_median_p3 == 0 | turnout_above_median_p3 == 2), absorb(mesa_code_elecspecific) cluster(mesa_code_elecspecific)
est store twoperiods_hte_turnout_6

* Make table
esttab twoperiods_hte_turnout_1 twoperiods_hte_turnout_2 twoperiods_hte_turnout_3 twoperiods_hte_turnout_4 twoperiods_hte_turnout_5 twoperiods_hte_turnout_6 using 03_tables/tabled1.tex, tex se replace mtitles ("Turnout above median" "Turnout below median" "Turnout above median" "Turnout below median" "Turnout above median" "Turnout below median")  keep (1.post 1.post#1.ep 1.post#1.ciutadella 1.post#1.ep#1.ciutadella 2.period) coeflabels (1.post "2019 election" 2.period "2014-2015 election" d1.post#1.ep "EP election in 2019" 1.post#1.ciutadella "Ciutadella in 2019" 1.post#1.ep "EP election in 2019" 1.post#1.ep#1.ciutadella "EP 2019 x Ciutadella" "2014-2015 election") star(* 0.10 ** 0.05 *** 0.01) addnotes("All models include voting station * election type fixed effects" "Standard errors are clustered by voting station * election type") 
